# Base image with PyTorch, CUDA 12.4, and cuDNN 9
# FROM pytorch/pytorch:2.5.1-cuda12.4-cudnn9-runtime
FROM python:3.12-slim

# Set working directory
WORKDIR /app

# Install system dependencies (including ffmpeg and other essentials)
RUN apt-get update && apt-get install -y \
    ffmpeg \
    libsndfile1 \
    && rm -rf /var/lib/apt/lists/*

# update packages
RUN apt-get update && apt-get install -y \
    ffmpeg \
    libsndfile1 \
    && rm -rf /var/lib/apt/lists/*

# install torch first
RUN pip install --no-cache-dir torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu

COPY requirements.txt /app/

# install requirements
RUN pip install --no-cache-dir -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple

# expose port
EXPOSE 12340 12341

# Copy only the necessary application files
COPY *.py /app/
COPY router/asr_api.py /app/router/asr_api.py
COPY router/asr_front.py /app/router/asr_front.py
COPY *.wav /app/
COPY models/punc_ct-transformer_cn-en-common-vocab471067-large /root/.cache/modelscope/hub/models/iic/punc_ct-transformer_cn-en-common-vocab471067-large
COPY models/streaming-paraformer-zh-en /root/.cache/modelscope/hub/models/damo/streaming-paraformer-zh-en
COPY models/speech_fsmn_vad_zh-cn-16k-common-pytorch /root/.cache/modelscope/hub/models/iic/speech_fsmn_vad_zh-cn-16k-common-pytorch
COPY models/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch /root/.cache/modelscope/hub/models/iic/speech_seaco_paraformer_large_asr_nat-zh-cn-16k-common-vocab8404-pytorch
COPY models/speech_campplus_sv_zh-cn_16k-common /root/.cache/modelscope/hub/models/iic/speech_campplus_sv_zh-cn_16k-common

# set start command
CMD ["python", "main_server.py"]